// 引入插件
import Vue from 'vue'
import Vuex from 'vuex'

// 引入接口
import { reqGetNavigationList, reqGetFloorsList, reqGetBannerList } from '@/api/index'
// 注册插件
Vue.use(Vuex)


// 定义方法
const state = {
    categoryList: [], //三级数据
    bannerList: [], // 轮播图数据
    floorsList: [] // 楼层数据

}
const actions = {

    // 获取三级数据
    async getCategoryList({ commit }) {
        const result = await reqGetNavigationList()
        if (result.code === 200) {
            commit('SetCategoryList', result.data)
        } else {
            console.log(result.message);
        }
    },

    // 获取轮播图数据
    async getBannerData({ commit }) {
        const result = await reqGetBannerList()
        if (result.code === 200) {
            commit('SetBannerList', result.data)
        } else {
            console.log(result.message);
        }
    },

    // 获取楼层数据
    async getFloorsData({ commit }) {
        const result = await reqGetFloorsList()
        if (result.code === 200) {
            commit('SetFloorsList', result.data)
        } else {
            console.log(result.message);
        }
    }
}
const mutations = {
    // 保存三级数据
    SetCategoryList(state, data) {
        state.categoryList = data
    },

    // 保存轮播图数据
    SetBannerList(state, data) {
        state.bannerList = data
    },

    // 保存楼层数据
    SetFloorsList(state, data) {
        state.floorsList = data
    }
}
const getters = {}


export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getters
}

